﻿package
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import mx.flash.UIMovieClip;
	[Bindable]
	[Event(name="fieldclick",type="FieldClickEvent")]
	public class Field extends mx.flash.UIMovieClip
	{
		public var _gold_mc:Sprite;
		public var _surface_mc:Sprite;
		public var _number_txt:TextField;
		
		public function Field()
		{
			super();
			this.addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
			this.addEventListener(MouseEvent.CLICK,onMouseClick);
			this.currentState="up";
			this.isgold=false;
		}
		protected function onMouseOver(event:MouseEvent):void
		{
			this.currentState="over";
		}
		
		protected function onMouseOut(event:MouseEvent):void
		{
			this.currentState="up";
		}
		
		protected function onMouseClick(event:MouseEvent):void 
		{
			this.currentState="dug";
			this.removeEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			this.removeEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
			this.removeEventListener(MouseEvent.CLICK,onMouseClick);
			this.dispatchEvent(new FieldEvent(FieldEvent.CLICK));
		} 
		
		public function set isgold(value:Boolean):void
		{
			_gold_mc.visible=value;
		}
		public function get isgold():Boolean
		{
			return _gold_mc.visible;
		}
		
		private var _displaynumber:int;
		public function set displaynumber(value:int):void
		{
			_displaynumber=value;
			if(value>0)
			{
				this._number_txt.text=value.toString();
			}
		}
		public function get displaynumber():int
		{
			return _displaynumber;
		}
	}
}